package com.danceforyou.common.util;

import com.danceforyou.common.restful.exception.BizException;
import com.danceforyou.common.restful.exception.BizExceptionEnum;

/**
 * 参数校验类（与springframework包Assert类相同）
 * @Auther danceforyou
 * 因springframework包Assert类抛出异常为IllegalArgumentException，无法因个人需求控制异常处理及异常信息展示，特此提供数据合法性校验工具类
 */
public abstract class AssertUtil {
    public AssertUtil() {
    }

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new BizException(message);
        }
    }

    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new BizException(message);
        }
    }

    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new BizException(message);
        }
    }

    public static void notNull(Object object, BizExceptionEnum exceptionEnum) {
        if (object == null) {
            throw new BizException(exceptionEnum.getCode(), exceptionEnum.getDesc());
        }
    }
}
